<?php

namespace App\Repository\GetWay;

use App\Models\GetWay\AppDouYinConfigModel as model;
use Illuminate\Support\Facades\Cache;
use App\Repository\RoleRepository;
use Illuminate\Support\Facades\DB;
use App\Repository\BaseRepository;
// use App\Repository\Order\OrderInfoRepository;

class AppDouYinConfigRepository extends  BaseRepository
{
  public function __construct()
  {
    $this->model = new model();
    // $this->modelInfo = new OrderInfoRepository();
    parent::__construct();
  }
  //添加 
  public function add($data)
  {
    //必填 字段
    $mustField = [
      'name',
      'path'
    ];
    $optionalFields = $this->model->getTableField();
    $msgField = [
      'name' => '通道名称不能为空',
      'path' => '通道路径不能为空',
    ];
    $insertData  = $this->getRealData($data, $mustField, $optionalFields, $msgField);
    if (!empty($insertData) && is_string($insertData)) {
      //返回错误参数
      return $this->returnMsg(
        2,
        $insertData
      );
    }
    $res = $this->model->insert($insertData);
    if ($res) {
      return $this->returnMsg(200, '添加成功');
    }
    return $this->returnMsg(1, '添加失败');
  }
  public function getOne($where, $field = ['*'])
  {
    return $this->model->where($where)->select($field)->first();
  }
  public function getCount($where)
  {
    return $this->model->where($where)->count();
  }
  public function getAllProduct($where)
  {
    return $this->model->where($where)->get()->toArray();
  }
  // 查询所有的信息
  public function getAllChannel($where, $field = ['*'])
  {
    return $this->model->where($where)->select($field)->get();
  }
}
